package timbap.visualizer.api.plugin;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import timbap.visualizer.api.context.PluginContext;

/**
 * The <code>AbstractPlugin</code> provides a common base
 * implementation of the <code>Plugin</code> interface
 * that should be used by all timbap plugins.
 *
 * @author  Andreas Pabst
 * @see     timbap.visualizer.api.plugin.Plugin
 */
public abstract class AbstractPlugin implements Plugin {

	private static final Log LOG = LogFactory.getLog(AbstractPlugin.class);

    PluginContext context;
	boolean initialized = false;
    boolean active = false;
	
    public void init(PluginContext pPluginContext) {
		context = pPluginContext;
		initialized = true;
	}

    public void activate() {
        active = true;
        if (LOG.isDebugEnabled()) {
            LOG.debug("plugin " + this.getClass().getSimpleName() + " has been activated.");
        }
	}

    public void passivate() {
        active = false;
        if (LOG.isDebugEnabled()) {
            LOG.debug("plugin " + this.getClass().getSimpleName() + " has been passivated.");
        }
	}

    public PluginContext getContext() {
        return context;
    }

    public boolean isInitialized() {
		return initialized;
	}

    public boolean isActive() {
        return active;
    }

    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        return true;
    }

    public int hashCode() {
        return getClass().hashCode();
    }
}
